//
//  planDetailsViewController.m
//  pb
//
//  Created by 千翼网络科技 on 2017/5/5.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "planDetailsViewController.h"

@interface planDetailsViewController ()

@property (nonatomic,strong) UIImageView *dateImg;
@property (nonatomic,strong) UILabel *monthLabel;
@property (nonatomic,strong) UILabel *dayLabel;
///
@property (nonatomic,strong) UILabel *numberLabel;

@property (nonatomic,strong) UILabel *startLocationLabel;
@property (nonatomic,strong) UILabel *startAirportLabel;
@property (nonatomic,strong) UILabel *startTimeLabel;

@property (nonatomic,strong) UIImageView *rightImg;
@property (nonatomic,strong) UILabel *allTimeLabel;

@property (nonatomic,strong) UILabel *endLocationLabel;
@property (nonatomic,strong) UILabel *endAirportLabel;
@property (nonatomic,strong) UILabel *endTimeLabel;

@property (nonatomic,strong) UITextView *messageTextView;

@end

@implementation planDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self loginIs];
    self.title = @"计划详情";
}

- (void)loginIs{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    [productParams setValue: [PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    
    [[MNetworkHandler sharedInstance]conURL:Login_is
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       
                                       [self requestData];
                                       
                                   }else{
                                       
                                       [PublicFunction showAlert:nil message:returnData[@"msg"] duration:10.0f];
                                       
                                       loginViewController *loginVc = [[loginViewController alloc]init];
                                       [self presentViewController:loginVc animated:YES completion:nil];
                                       
                                   }
                               } failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];
}

- (void)requestData{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    [productParams setValue: [PublicFunction getConfigWithKey:@"token"] forKey:@"token"];
    [productParams setValue: _idStr forKey:@"id"];
    
//    [productParams setValue: @"" forKey:@"token"];
//    [productParams setValue: @"3" forKey:@"id"];
    
    [[MNetworkHandler sharedInstance]conURL:Plan_Details
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       
                                       _dataDic = [[NSMutableDictionary alloc]init];
                                       _dataDic = returnData;
                                       [self reloadView];
                                       
                                   }else{
                                       
                                       [PublicFunction showAlert:nil message:@"今日没有行程" duration:5.0f];
                                       
                                   }
                               } failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];
}

- (void)reloadView{
    
    _monthLabel.text = _dataDic[@"month"];
    _dayLabel.text = _dataDic[@"day"];

    _numberLabel.text = _dataDic[@"name"];
    
    _startLocationLabel.text = _dataDic[@"start_city"];
    _startAirportLabel.text = _dataDic[@"start_airport"];
    _startTimeLabel.text = _dataDic[@"start_time"];
    
    _allTimeLabel.text = _dataDic[@"time"];
    
    _endLocationLabel.text = _dataDic[@"end_city"];
    _endAirportLabel.text = _dataDic[@"end_airport"];
    _endTimeLabel.text = _dataDic[@"end_time"];
    
    _messageTextView.text = _dataDic[@"content"];
}

- (void)initView{
    
    _dateImg = [[UIImageView alloc]init];
    _dateImg.image = [UIImage imageNamed:@"date_plan"];
    [self.view addSubview:_dateImg];
    [_dateImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(screenScale(40));
        make.left.mas_equalTo(self.view).with.offset(screenScale(250));
        make.width.mas_equalTo(screenScale(140));
        make.height.mas_equalTo(screenScale(140));
    }];
    
    _monthLabel = [[UILabel alloc]init];
//    _monthLabel.text = @"MAY";
    _monthLabel.font = get4sFont(11);
    _monthLabel.textAlignment = NSTextAlignmentCenter;
    _monthLabel.textColor = getColor(@"ffffff");
    [self.view addSubview:_monthLabel];
    [_monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_dateImg).with.offset(screenScale(5));
        make.left.mas_equalTo(_dateImg).with.offset(0);
        make.width.mas_equalTo(screenScale(140));
        make.height.mas_equalTo(screenScale(40));
    }];
    
    _dayLabel = [[UILabel alloc]init];
//    _dayLabel.text = @"2";
    _dayLabel.font = get4sFont(30);
    _dayLabel.textAlignment = NSTextAlignmentCenter;
    _dayLabel.textColor = getColor(@"ffffff");
    [self.view addSubview:_dayLabel];
    [_dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_dateImg).with.offset(0);
        make.left.mas_equalTo(_dateImg).with.offset(0);
        make.width.mas_equalTo(screenScale(140));
        make.height.mas_equalTo(screenScale(100));
    }];
    
    //////////////////////////
    
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = getMainColor();
    bgView.layer.cornerRadius = screenScale(10);
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_dateImg.mas_bottom).with.offset(screenScale(67));
        make.left.mas_equalTo(self.view).with.offset(screenScale(53));
        make.width.mas_equalTo(scrWidth() - screenScale(53)*2);
        make.height.mas_equalTo(screenScale(666));
    }];
    
    _numberLabel = [[UILabel alloc]init];
//    _numberLabel.text = @"南方航空 CZ545";
    _numberLabel.textColor = getColor(@"ffffff");
    _numberLabel.textAlignment = NSTextAlignmentCenter;
    _numberLabel.font = get4sFont(14);
    [bgView addSubview:_numberLabel];
    [_numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView).with.offset(screenScale(40));
        make.left.mas_equalTo(bgView).with.offset(0);
        make.right.mas_equalTo(bgView).with.offset(0);
        make.height.mas_equalTo(screenScale(28));
    }];
    
    _startLocationLabel = [[UILabel alloc]init];
//    _startLocationLabel.text = @"巴基斯坦";
    _startLocationLabel.textColor = getColor(@"ffffff");
    _startLocationLabel.textAlignment = NSTextAlignmentCenter;
    _startLocationLabel.font = get4sFont(13);
    [bgView addSubview:_startLocationLabel];
    [_startLocationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView).with.offset(screenScale(120));
        make.left.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(24));
    }];
    
    _startAirportLabel = [[UILabel alloc]init];
//    _startAirportLabel.text = @"巴基斯坦机场";
    _startAirportLabel.textColor = getColor(@"ffffff");
    _startAirportLabel.textAlignment = NSTextAlignmentCenter;
    _startAirportLabel.font = get4sFont(13);
    [bgView addSubview:_startAirportLabel];
    [_startAirportLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startLocationLabel.mas_bottom).with.offset(screenScale(35));
        make.left.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(24));
    }];
    
    _startTimeLabel = [[UILabel alloc]init];
//    _startTimeLabel.text = @"9:00";
    _startTimeLabel.textColor = getColor(@"ffffff");
    _startTimeLabel.textAlignment = NSTextAlignmentCenter;
    _startTimeLabel.font = get4sFont(15);
    [bgView addSubview:_startTimeLabel];
    [_startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startAirportLabel.mas_bottom).with.offset(screenScale(35));
        make.left.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(26));
    }];
    
    ///
    
    _rightImg = [[UIImageView alloc]init];
    _rightImg.image = [UIImage imageNamed:@"arroiw"];
    [bgView addSubview:_rightImg];
    [_rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startLocationLabel.mas_bottom).with.offset(screenScale(3));
        make.left.mas_equalTo(bgView).with.offset(screenScale(250));
        make.width.mas_equalTo(screenScale(46));
        make.height.mas_equalTo(screenScale(18));
    }];
    
    _allTimeLabel = [[UILabel alloc]init];
//    _allTimeLabel.text = @"3个小时03分";
    _allTimeLabel.textColor = getColor(@"ffffff");
    _allTimeLabel.textAlignment = NSTextAlignmentCenter;
    _allTimeLabel.font = get4sFont(13);
    [bgView addSubview:_allTimeLabel];
    [_allTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startTimeLabel).with.offset(screenScale(3));
        make.left.mas_equalTo(bgView).with.offset(screenScale(175));
        make.width.mas_equalTo(screenScale(535) - screenScale(175)*2);
        make.height.mas_equalTo(screenScale(24));
    }];
    
    ///
    
    _endLocationLabel = [[UILabel alloc]init];
//    _endLocationLabel.text = @"阿富汗";
    _endLocationLabel.textColor = getColor(@"ffffff");
    _endLocationLabel.textAlignment = NSTextAlignmentCenter;
    _endLocationLabel.font = get4sFont(13);
    [bgView addSubview:_endLocationLabel];
    [_endLocationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView).with.offset(screenScale(120));
        make.right.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(24));
    }];
    
    _endAirportLabel = [[UILabel alloc]init];
//    _endAirportLabel.text = @"阿富汗机场";
    _endAirportLabel.textColor = getColor(@"ffffff");
    _endAirportLabel.textAlignment = NSTextAlignmentCenter;
    _endAirportLabel.font = get4sFont(13);
    [bgView addSubview:_endAirportLabel];
    [_endAirportLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startLocationLabel.mas_bottom).with.offset(screenScale(35));
        make.right.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(24));
    }];
    
    _endTimeLabel = [[UILabel alloc]init];
//    _endTimeLabel.text = @"12:03";
    _endTimeLabel.textColor = getColor(@"ffffff");
    _endTimeLabel.textAlignment = NSTextAlignmentCenter;
    _endTimeLabel.font = get4sFont(15);
    [bgView addSubview:_endTimeLabel];
    [_endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_startAirportLabel.mas_bottom).with.offset(screenScale(35));
        make.right.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(screenScale(175));
        make.height.mas_equalTo(screenScale(26));
    }];
    
    UIView *threadView = [[UIView alloc]init];
    threadView.backgroundColor = getColor(@"ffffff");
    [bgView addSubview:threadView];
    [threadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_endTimeLabel.mas_bottom).with.offset(screenScale(25));
        make.left.mas_equalTo(bgView).with.offset(0);
        make.width.mas_equalTo(scrWidth() - screenScale(53)*2);
        make.height.mas_equalTo(screenScale(1));
    }];
    
    ///
    
    _messageTextView = [[UITextView alloc]init];
    _messageTextView.editable = NO;
    _messageTextView.backgroundColor = getMainColor();
    [bgView addSubview:_messageTextView];
    [_messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(threadView.mas_bottom).with.offset(screenScale(25));
        make.left.mas_equalTo(bgView).with.offset(screenScale(25));
        make.right.mas_equalTo(bgView).with.offset(screenScale(-5));
        make.bottom.mas_equalTo(bgView).with.offset(screenScale(-25));
    }];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = screenScale(10);// 字体的行间距
    
    NSDictionary *attributes = @{NSParagraphStyleAttributeName:paragraphStyle};
    _messageTextView.attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:attributes];
    _messageTextView.textColor = getColor(@"ffffff");
    _messageTextView.font = get4sFont(12);
}

@end
